﻿using System;

namespace Zive.Color {

    public class LabColorSpaceChannelInfoCollection: ColorSpaceChannelInfoCollection {

        //
        // Interface
        //

        internal LabColorSpaceChannelInfoCollection( ) { }

        public override ColorSpaceChannelInfo this[ int index ] {
            get { return _channelInfoCollection[ index ]; }
        }

        //
        // Implementation
        //

        private class LstarLabColorSpaceChannelInfo: ColorSpaceChannelInfo<LabChannels> {

            public override LabChannels Value {
                get { return LabChannels.L; }
            }

            public override int IntegerValue {
                get { return (int) LabChannels.L; }
            }

            public override string Name {
                get { return "L*"; }
            }

            public override double MinimumValue {
                get { return 0d; }
            }

            public override double MaximumValue {
                get { return 100d; }
            }

            public override double Range {
                get { return 100d; }
            }

        }

        private class OtherLabColorSpaceChannelInfo: ColorSpaceChannelInfo<LabChannels> {

            public OtherLabColorSpaceChannelInfo( LabChannels channel, string name ) {
                _channel = channel;
                _name = name;
            }

            public override LabChannels Value {
                get { return _channel; }
            }

            public override int IntegerValue {
                get { return (int) _channel; }
            }

            public override string Name {
                get { return _name; }
            }

            public override double MinimumValue {
                get { return -128d; }
            }

            public override double MaximumValue {
                get { return 128d; }
            }

            public override double Range {
                get { return 256d; }
            }

            private readonly LabChannels _channel;
            private readonly string _name;

        }

        private static readonly ColorSpaceChannelInfo<LabChannels>[ ] _channelInfoCollection = {
            new LstarLabColorSpaceChannelInfo( ),
            new OtherLabColorSpaceChannelInfo( LabChannels.A, "a*" ),
            new OtherLabColorSpaceChannelInfo( LabChannels.B, "b*" ),
        };

    }

    public class LabColorSpaceInfo: ColorSpaceInfo<LabColor> {

        //
        // Interface
        //

        public override string Name {
            get { return "CIE 1976 L*a*b*"; }
        }

        public override string Label {
            get { return "L*a*b*"; }
        }

        public override int NumberOfChannels {
            get { return 3; }
        }

        public override Type ColorType {
            get { return typeof( LabColor ); }
        }

        public override Type ChannelsType {
            get { return typeof( LabChannels ); }
        }

        public override Type ConverterType {
            get { return typeof( LabColorConverter ); }
        }

        public override ColorSpaceChannelInfoCollection Channels {
            get { return _channelInfoCollection; }
        }

        public override LabColor CreateColorInstance( ) {
            return new LabColor( );
        }

        //
        // Implementation
        //

        private static readonly ColorSpaceChannelInfoCollection _channelInfoCollection = new LabColorSpaceChannelInfoCollection( );

    }

}
